package com.backend.demo.util;

import java.util.Date;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.Converter;

import com.opensymphony.xwork2.conversion.impl.DateConverter;

public class ConvertUtil {
	public static Object convert(String value, Class clazz) {
		if (value == null || clazz == null) {
			return null;
		}
		ConvertUtils.register((Converter) new DateConverter(), Date.class);
		Object ret = ConvertUtils.convert(value, clazz);
		ConvertUtils.deregister(Date.class);
		return ret;
	}

	public static Object convert(String[] values, Class clazz) {
		ConvertUtils.register((Converter) new DateConverter(), Date.class);
		Object convert = ConvertUtils.convert(values, clazz);
		ConvertUtils.deregister(Date.class);
		return convert;
	}
}
